package com.youkeda.yunmusic.web.control;

import com.youkeda.yunmusic.web.modle.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
/**
 * @Author ming
 * @DATE 2019/3/26.
 */
@Controller
public class CommentLikeControl {
    @Autowired
    private CommentPostControl commentPostControl;

    @ResponseBody
    @RequestMapping(path = "/comment/like")
    public Comment like(@RequestParam("songId") String songId , @RequestParam("commentId") String commentId) {
        List <Comment> commentList = commentPostControl.getComments(songId);
        Comment result = null;
        for (Comment comment : commentList) {
            if (!comment.getId().equals(commentId)) {
                continue;
            }

            comment.setLikeNum(comment.getLikeNum() + 1);
            result = comment;


        }
        return result;
    }
}